package com.funtl.screw.common.security.component;

import com.funtl.screw.common.core.constant.SecurityConstants;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;

/**
 * @author Lusifer
 * @since 2020/9/29
 * <p>
 * redis token store 自动配置
 */
@RequiredArgsConstructor
@Configuration(proxyBeanMethods = false)
public class ServiceTokenStoreAutoConfiguration {

    private final RedisConnectionFactory connectionFactory;

    @Bean
    public TokenStore tokenStore() {
        ServiceRedisTokenStore tokenStore = new ServiceRedisTokenStore(connectionFactory);
        tokenStore.setPrefix(SecurityConstants.SERVICE_PREFIX + SecurityConstants.OAUTH_PREFIX);
        return tokenStore;
    }

}
